package com.ruoyi.ly.controller;

import com.ruoyi.ly.domain.dto.MobileIndustryAddDTO;
import com.ruoyi.ly.domain.dto.MobileIndustryUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileIndustryDTO;
import com.ruoyi.ly.domain.vo.MobileIndustryVO;
import com.ruoyi.ly.service.MobileIndustryService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobile/industry")
@Api("合作企业接口")
@Slf4j
public class MobileIndustryController {
    
    @Autowired
    private MobileIndustryService mobileIndustryService;


    //  新增合作企业信息
    @PostMapping("/add")
    @ApiOperation(value = "新增合作企业信息")
    public Result<String> insert(@RequestBody MobileIndustryAddDTO mobileIndustryDTO){
        log.info("新增合作企业信息");
        mobileIndustryService.save(mobileIndustryDTO);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result<PageResult> page(PageMobileIndustryDTO pageMobileIndustryDTO) {
        log.info("分页查询：{}", pageMobileIndustryDTO);
        PageResult pageResult = mobileIndustryService.pageQuery(pageMobileIndustryDTO);
        return Result.success(pageResult);
    }

    //删除合作企业
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除合作企业")
    public Result delete(@PathVariable("id")Long id) {
        log.info("删除合作企业：{}", id);
        mobileIndustryService.delete(id);
        return Result.success();
    }

    //修改合作企业
    @PutMapping("/update")
    @ApiOperation(value = "修改合作企业")
    public Result update(@RequestBody MobileIndustryUpdateDTO mobileIndustryUpdateDto) {
        log.info("修改合作企业：{}", mobileIndustryUpdateDto);
        mobileIndustryService.update(mobileIndustryUpdateDto);
        return Result.success();
    }

    //根据合作企业id查询合作企业详情
    @GetMapping("/{id}")
    @ApiOperation(value = "根据合作企业id查询合作企业详情")
    public  Result<MobileIndustryVO> selectById(@PathVariable Long id) {
        log.info("根据合作企业id查询合作企业详情：{}",id);
        MobileIndustryVO mobileIndustryVO = mobileIndustryService.selectById(id);
        return Result.success(mobileIndustryVO);
    }
}
